import { uploadJoin } from "../../../utils/request/api";
import msg from "../../../utils/msg";
import { formatTime } from '../../../utils/util';
import User from "../../../utils/user";
var user = new User;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    addContent: {
      title: '' as string,
      place: '' as string,
      start_time: '' as string,
      end_time: '' as string,
      people: '' as string,
      s_name: user.getInfo().name,
      s_code: user.getInfo().code
    },
    showtime1: false,
    showtime2: false,
    minHour: 0,
    maxHour: 24,
    currentDate: new Date().getTime(),
  },

  //提交
  submit: async function () {
    msg.Loading('正在发布');
    await uploadJoin(this.data.addContent).then(() => { wx.navigateBack(); });
  },

  //获取输入
  getInput(e: any) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      ['addContent.' + index]: e.detail.value,
    });
  },

  //获取开始时间
  getInputStart(event: any) {
    let addContent = this.data.addContent;
    addContent.start_time = formatTime(new Date(event.detail));
    console.log(addContent.start_time);
    this.setData({
      addContent: addContent,
      showtime1: false,
    });
  },

  //获取结束时间
  getInputEnd(event: any) {
    let addContent = this.data.addContent;
    addContent.end_time = formatTime(new Date(event.detail));
    this.setData({
      addContent: addContent,
      showtime2: false,
    });
  },

  //关闭弹窗
  onClose() {
    this.setData({
      showtime1: false,
      showtime2: false,
    })
  },

  //选择开始时间
  onChooseTime1() {
    this.setData({
      showtime1: true,
    })
  },

  //选择结束时间
  onChooseTime2() {
    this.setData({
      showtime2: true,
    })
  },

  //返回
  onClickLeft() {
    wx.navigateBack();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})